/**********************************************************************
 *                                                                    *
 * tgt - Tiny Graphics Toolbox                                        *
 *                                                                    *
 * Copyright (C) 2006-2008 Visualization and Computer Graphics Group, *
 * Department of Computer Science, University of Muenster, Germany.   *
 * <http://viscg.uni-muenster.de>                                     *
 *                                                                    *
 * This file is part of the tgt library. This library is free         *
 * software; you can redistribute it and/or modify it under the terms *
 * of the GNU Lesser General Public License version 2.1 as published  *
 * by the Free Software Foundation.                                   *
 *                                                                    *
 * This library is distributed in the hope that it will be useful,    *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the       *
 * GNU Lesser General Public License for more details.                *
 *                                                                    *
 * You should have received a copy of the GNU Lesser General Public   *
 * License in the file "LICENSE.txt" along with this library.         *
 * If not, see <http://www.gnu.org/licenses/>.                        *
 *                                                                    *
 **********************************************************************/

#ifndef TGT_TOPVIEWNAVIGATION_H
#define TGT_TOPVIEWNAVIGATION_H

#include "tgt/config.h"
#include "tgt/camera.h"
#include "tgt/event/mouseevent.h"
#include "tgt/vector.h"
#include "tgt/glcanvas.h"
#include "tgt/navigation/navigation.h"


namespace tgt {

class TopviewNavigation : public Navigation {
public:

    TopviewNavigation(
        GLCanvas* canvas,
        tgt::Camera* camera,
        int button1,
        int button2,
        int button3
    );

    virtual ~TopviewNavigation();

    void setMoveSensitivity(double s) { moveSensitivity_ = s; }
    double getMoveSensitivity() const { return moveSensitivity_; }
    void setZoomSensitivity(double s) { zoomSensitivity_ = s; }
    double getZoomSensitivity() const { return zoomSensitivity_; }
    void setTurnSensitivity(double s) { turnSensitivity_ = s; }
    double getTurnSensitivity() const { return turnSensitivity_; }

    void onEvent(Event*);

private:
    GLCanvas* canvas_;
    Camera* camera_;
    double moveSensitivity_;
    double zoomSensitivity_;
    double turnSensitivity_;

    int moveButton_;
    int zoomButton_;
    int turnButton_;
    bool moveButtonPressed_;
    bool zoomButtonPressed_;
    bool turnButtonPressed_;
    bool move_;

    int currentX_;
    int currentY_;
    int count_;
    double xValue_;
    double yValue_;
    vec3 from_;
    vec3 to_;
    vec3 up_;
    vec3 dir_;
    vec3 right_;
    vec3 gogo_;
    vec3 y_up_;
    vec3 focusPoint_;
    vec3 moveStart_;

    GLint viewport_[4];
    GLdouble mvmatrix_[16], projmatrix_[16];
    
    vec3 getProjectedCursorCoordinates(int x, int y, GLint viewport[4], GLdouble mvmatrix[16], GLdouble projmatrix[16], bool ground);
};

} // namespace tgt

#endif // TGT_TOPVIEWNAVIGATION_H
